﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TpLogic.Hamurabi;

namespace TpTests.HamHostApp
{
    public partial class _Default : System.Web.UI.Page
    {
        Random r = new Random(5);

        HamurabiGame foo;

        GameState state 
        {
            get 
            {
                if (ViewState["state"] == null)
                {
                    GameState state = foo.InitialGameState();
                    ViewState["state"] = state;
                    return state;
                }
                return (GameState) ViewState["state"];
            }

            set 
            {
                ViewState["state"] = value; 
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            
            foo = new HamurabiGame(r, new AspNetConsole(InputBox, ConsoleLabel));
            if (!IsPostBack)
            {
                foo.PlayHammurabi(state);
            }
        }

        protected void EnterButton_Click(object sender, EventArgs e)
        {
            if(!state.gameOver)
                foo.PlayHammurabi(state);
        }
    }
}
